package com.jxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RestController  json ����
//@RefreshScope   此参数需要加入到注解对应的类才能生效

@RestController
@RefreshScope
public class clientTestController {
	@Autowired
	private DiscoveryClient discoveryClient;
	@Value("${test}")
	private String value;

	@RequestMapping(value = "/getValue")
	public String getValue() {
		System.out.println("-------------------getValue-----------------");
		return value;
	}

	@RequestMapping(value = "/add")
	public Integer add(@RequestParam Integer a, @RequestParam Integer b) {
		ServiceInstance instance = discoveryClient.getLocalServiceInstance();
		System.out.println("host:" + instance.getHost() + "   port :"
				+ instance.getPort() + "   service_id :"
				+ instance.getServiceId());
		return a + b;
	}
}
